<?php
  require '../include/library.inc.php';
  require '../include/admin_login.inc.php';
    
  $course_id = intval($_GET['course_id']);
  $school_id = intval($_GET['school_id']);

  if($course_id) {
	
	$sql = "SELECT
			  order_id
			FROM
			  orders
			WHERE
			  course_id = ".$course_id." 
              ";
	$row = mysql_fetch_assoc(query($sql));
	
	if (!$row['order_id']) { // If now orders with this course	
	
		$sql = "DELETE FROM 
				   course_dates
				WHERE
				   course_id = ".$course_id." 
				 ";
		query($sql);
		
		$sql = "DELETE FROM 
				   courses
				WHERE
				   course_id = ".$course_id." 
				 ";
		query($sql);
		
		$_SESSION['message'] = 'Successfully deleted!';
	
	} else {
		
		$_SESSION['message'] = 'There is orders with this course!';
		
	}
	
	
  }
  
  redirect("school_edit.php?school_id=".$school_id."#courses");
 
?>